﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace Bitcoin.Diagnostics
{
    public class NetLog : ILog
    {
        private TraceSource _trace;

        public NetLog(Type type)
        {
            var name = type.Assembly.GetName().Name;
            _trace = new TraceSource(name);
        }

        public void DebugFormat(string format, params object[] args)
        {
            _trace.TraceEvent(TraceEventType.Verbose, 0, format, args);
        }

        public void Error(string message)
        {
            _trace.TraceEvent(TraceEventType.Error, 0, message);
        }

        public void Error(string message, Exception e)
        {
            _trace.TraceEvent(TraceEventType.Error, 0, message + ";" + e.ToString());
        }

        public void ErrorFormat(string format, params object[] args)
        {
            _trace.TraceEvent(TraceEventType.Error, 0, format, args);
        }

        public void ErrorFormat(string format, Exception e, params object[] args)
        {
            _trace.TraceEvent(TraceEventType.Error, 0, format + ";" + e.ToString(), args);
        }

        public void Info(string message)
        {
            _trace.TraceEvent(TraceEventType.Information, 0, message);
        }

        public void InfoFormat(string format, params object[] args)
        {
            _trace.TraceEvent(TraceEventType.Information, 0, format, args);
        }

        public bool IsDebugEnabled
        {
            get { return _trace.Switch.ShouldTrace(TraceEventType.Verbose); }
            set { }
        }

        public bool IsInfoEnabled
        {
            get { return _trace.Switch.ShouldTrace(TraceEventType.Information); }
            set { }
        }

        public void Warn(string message)
        {
            _trace.TraceEvent(TraceEventType.Warning, 0, message);
        }

        public void Warn(string message, Exception e)
        {
            _trace.TraceEvent(TraceEventType.Warning, 0, message + ";" + e.ToString());
        }

        public void WarnFormat(string format, params object[] args)
        {
            _trace.TraceEvent(TraceEventType.Warning, 0, format, args);
        }
    }
}
